﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;

namespace QL_KHACHSAN.Forms
{
    public partial class frmDangNhap : Office2007Form
    {
        private string strError = "Hệ thống phát hiện lỗi\nXin hãy liên hệ Dương Kỳ Hiệu\nĐT:0907774982\n\n";
        public frmDangNhap()
        {
            InitializeComponent();
        }
        private void EnterDangNhap()
        {
            try
            {
                string strSQL = "";
                string strUser = txtUser.Text;
                string strPassword = txtPassword.Text;
                strSQL = "select code from Users where data= " + "'" + strUser + "' and Matkhau ='" + strPassword + "'";
                ADODB.Recordset Rs = new ADODB.Recordset();
                Rs.Open(strSQL, clsMain.flexConn.fcConn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockReadOnly, -1);
                if (Rs.RecordCount > 0)
                {
                    clsMain.booLogin = true;
                    clsMain.strUserLogin = Convert.ToString(Rs.Fields[0].Value);
                    this.Close();
                    
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(strError + ex.ToString());
            }
            
        }

        private void frmDangNhap_KeyDown(object sender, KeyEventArgs e)
        {
            try 
            {
                if (e.KeyCode.Equals(System.Windows.Forms.Keys.Enter))
                {
                    EnterDangNhap();
                }
                else if (e.KeyCode.Equals(System.Windows.Forms.Keys.Escape))
                {
                    this.Close();
                }
            }
            catch(Exception ex  )
            {
                MessageBox.Show(strError + ex.ToString());
            }

           
        }

        private void butDangNhap_Click(object sender, EventArgs e)
        {
            EnterDangNhap();
        }

        private void butThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
